/*
 * \file ClassWidget.cpp
 *
 * \date Created on: Jan 21, 2009
 * \author sarah
 */

#include "ClassWidget.h"

#include <DndData/CharacterData.h>
#include <Models/XmlDirModel.h>

#include <QDebug>

ClassWidget::ClassWidget(CharacterData *data, QWidget *parent)
	: QWidget(parent)
        , mData(data)
        , mDirModel(new XmlDirModel(this))
{
    mPage.setupUi(this);
    mDirModel->setFilter(QDir::Files);
    mPage.classPowersTreeView->setModel(mDirModel);
}

ClassWidget::~ClassWidget()
{
}

void ClassWidget::updateToClass(const QString &className)
{
    if (className != mCurrentClass)
    {
        mCurrentClass = className;
        XmlPath xmlPath(XmlPath::CLASS_BASE, mCurrentClass);
        xmlPath.setSubType(XmlPath::POWER_TYPE);
        QDir typeDir = xmlPath.dir();
        qDebug() << "focus on typeDir" << typeDir.absolutePath();
        QModelIndex rootIndex = mDirModel->index(typeDir.absolutePath());
        mPage.classPowersTreeView->setRootIndex(rootIndex);
        mDirModel->refresh(rootIndex);
    }
}
